<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('考勤状态变动登记')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: select2-css"/>
    <th:block th:include="include :: bootstrap-editable-css"/>

</head>
<body class="gray-bg">
<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="user-form">
                    <div class="select-list">
                        <ul>
                            <li>
                                姓名：<input type="text" name="name"/>
                            </li>
                            <li>
                                工号：<input type="text" name="badge"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                        class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                        class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addFull()">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary" onclick="entryEdit()">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()">
                    <i class="fa fa-remove"></i> 删除
                </a>
                &nbsp;&nbsp;&nbsp;
                <a class="btn btn-primary" onclick="check('asp_changecheck')">
                    <i class="fa fa-edit"></i> 确认检查
                </a>
                <a class="btn btn-danger" onclick="check('asp_changecancel')">
                    <i class="fa fa-remove"></i> 取消确认
                </a>
                <a class="btn btn-primary" onclick="check('asp_changestart')">
                    执行变动
                </a>
            </div>

            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>
<th:block th:include="include :: ztree-js"/>

<script th:inline="javascript">
    var prefix = ctx + "attendEmpManage/AttendChange";
    $(function () {
        queryData();
    });

    function entryEdit() {
        var row = $("#bootstrap-table").bootstrapTable('getSelections');
        if (row.length == 0) {
            $.modal.alertWarning("请选择要修改的数据");
            return;
        }
        if (row.length > 1) {
            $.modal.alertWarning("只能选择一条数据");
            return;
        }
        $.operate.editFull();
    }

    function queryData() {
        var columns = [];
        var checkbox = {checkbox: true};
        var id = {field: 'id', title: '序号'};
        var term = {field: 'term', title: '登记日期'};
        var badge = {field: 'badge', title: '工号'};
        var name = {field: 'name', title: '姓名'};
        var compName = {field: 'compName', title: '公司名称'};
        var depName = {field: 'depName', title: '部门名称'};
        var jobName = {field: 'jobName', title: '工作岗位'};
        var atStatusOld = {field: 'atStatusOld', title: '考勤状态（旧）'};
        var atStatusNew = {field: 'atStatusNew', title: '考勤状态（新）'};
        var beginDate = {field: 'beginDate', title: '开始日期'};
        var remark = {field: 'remark', title: '备注'};
        var initialized = {
            field: 'initialized',
            title: '是否确认',
            formatter: function (value, row, index) {
                return showCheck(row);
            }
        };
        var initializedName = {field: 'initializedName', title: '确认人'};
        var initializedTime = {field: 'initializedTime', title: '确认时间'};

        columns.push(checkbox, id, term, badge, name, compName, depName, jobName, atStatusOld, atStatusNew, initialized, initializedName,
            initializedTime, beginDate, remark);

        var options = {
            uniqueId: "id",
            url: prefix + "/status",
            createUrl: prefix + "/addStatus",
            updateUrl: prefix + "/editStatus/{id}",
            removeUrl: prefix + "/remove",
            height: $(window).height() - 120,
            sortOrder: "desc",
            modalName: "考勤状态变动登记",
            columns: columns
        };
        $.table.init(options);
    }

    function showCheck(row) {
        if (row.isdxsj) {
            return '<i class="fa fa-toggle-on text-info fa-2x"></i> ';
        } else {
            return '<i class="fa fa-toggle-off text-info fa-2x"></i> ';
        }
    }

    function check(procedure) {
        var allId = "";
        var allName = "";
        var row = $("#bootstrap-table").bootstrapTable('getSelections');
        if (row.length == 0) {
            $.modal.alertWarning("请选择一条职员");
            return;
        }
        for (var i = 0; i < row.length; i++) {
            if (i == row.length - 1) {
                allId += row[i].id;
                allName += row[i].name;
            } else {
                allId += row[i].id + ",";
                allName += row[i].name + ",";
            }
        }
        $.ajax({
            url: prefix + "/procedure",
            data: {"allId": allId, "allName": allName, "procedure": procedure},
            type: "post",
            dataType: "json",
            success: function (data) {
                if (data.data == null) {
                    $.modal.alertWarning(data.message);
                } else {
                    $.modal.alertSuccess(data.data);
                }
                $.table.refresh();
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                $.modal.alertWarning("错误,请联系管理员,错误信息:" + textStatus);
            }
        });
    }

</script>
</body>
</html>